<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Class: ActiveBackground::Job</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />

    <script language="JavaScript" type="text/javascript">
    // <![CDATA[

        function toggleSource( id )
        {
          var elem
          var link

          if( document.getElementById )
          {
            elem = document.getElementById( id )
            link = document.getElementById( "l_" + id )
          }
          else if ( document.all )
          {
            elem = eval( "document.all." + id )
            link = eval( "document.all.l_" + id )
          }
          else
            return false;

          if( elem.style.display == "block" )
          {
            elem.style.display = "none"
            link.innerHTML = "show source"
          }
          else
          {
            elem.style.display = "block"
            link.innerHTML = "hide source"
          }
        }

        function openCode( url )
        {
          window.open( url, "SOURCE_CODE", "width=400,height=400,scrollbars=yes" )
        }
      // ]]>
    </script>

  </head>

  <body>
  <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
  <td class="file-title"><span class="file-title-prefix">Class</span><br />ActiveBackground::Job</td>
  <td align="right">
    <table cellspacing=0 cellpadding=2>
      <tr valign="top">
        <td>In:</td>
        <td>

<a href="../../files/vendor/plugins/active_background/tasks/__/lib/active_background/job_rb.html">vendor/plugins/active_background/tasks/../lib/active_background/job.rb</a>
        </td>
      </tr>
    <tr>
      <td>Parent:</td>
      <td>
        <a href="Base.html">
Base
         </a>

     </td>
   </tr>
         </table>
        </td>
        </tr>
      </table>
 <!-- banner header -->

  <div id="bodyContent">
      <div id="content">




  <div class="sectiontitle">Methods</div>
  <ul>
  <li><a href="#M000113">archive</a></li>
  <li><a href="#M000124">args</a></li>
  <li><a href="#M000109">define_job</a></li>
  <li><a href="#M000130">dump</a></li>
  <li><a href="#M000140">gen_key</a></li>
  <li><a href="#M000111">initiate_termination</a></li>
  <li><a href="#M000125">job_args</a></li>
  <li><a href="#M000117">job_key</a></li>
  <li><a href="#M000119">job_progress</a></li>
  <li><a href="#M000129">job_statistic</a></li>
  <li><a href="#M000127">job_statistics</a></li>
  <li><a href="#M000121">job_status</a></li>
  <li><a href="#M000123">job_status=</a></li>
  <li><a href="#M000134">job_valid</a></li>
  <li><a href="#M000136">job_valid=</a></li>
  <li><a href="#M000116">key</a></li>
  <li><a href="#M000115">name</a></li>
  <li><a href="#M000106">new</a></li>
  <li><a href="#M000137">no_valid_results</a></li>
  <li><a href="#M000107">process</a></li>
  <li><a href="#M000108">process_job</a></li>
  <li><a href="#M000118">progress</a></li>
  <li><a href="#M000114">recover_from_archive</a></li>
  <li><a href="#M000139">start</a></li>
  <li><a href="#M000128">statistic</a></li>
  <li><a href="#M000126">statistics</a></li>
  <li><a href="#M000120">status</a></li>
  <li><a href="#M000122">status=</a></li>
  <li><a href="#M000138">stop</a></li>
  <li><a href="#M000110">terminate</a></li>
  <li><a href="#M000112">terminated?</a></li>
  <li><a href="#M000133">valid</a></li>
  <li><a href="#M000135">valid=</a></li>
  <li><a href="#M000131">valid?</a></li>
  <li><a href="#M000132">validate</a></li>
  </ul>


<div class="sectiontitle">Included Modules</div>
<ul>
  <li><a href="DatabaseHandler.html">ActiveBackground::DatabaseHandler</a></li>
</ul>






<div class="sectiontitle">Public Class methods</div>
<div class="method">
  <div class="title">
    <a name="M000106"></a><b>new</b>(name, options={}, *args)
  </div>
  <div class="description">

  <p>
Arguments:
</p>
<pre>
  &lt;tt&gt;name&lt;/tt&gt;: Name of the job (doesn't have to be uniq but similar jobs should get the same name)j
  &lt;tt&gt;options&lt;/tt&gt;: Options that configure the internal workings of the job (you can only pass these on initiation)
  &lt;tt&gt;args&lt;/tt&gt;: Arguments are passed to the method process_job
</pre>
<p>
Options:
</p>
<pre>
  &lt;tt&gt;:terminate&lt;/tt&gt;: Specify if job should be terminated when processed (default true)
  &lt;tt&gt;:postpone_termination&lt;/tt&gt;: Time in seconds to post pone termination (default false)
  &lt;tt&gt;:before_job&lt;/tt&gt;: call before_job method before process_job (default false)
  &lt;tt&gt;:after_job&lt;/tt&gt;: call after_job method after process_job (default false)
  &lt;tt&gt;:cleanup&lt;/tt&gt;: call cleanup after everything is done (default false)
  &lt;tt&gt;:archive&lt;/tt&gt;: archive the job (default true)
  &lt;tt&gt;:ttl&lt;/tt&gt;: time in seconds to wait before terminating job (:infinitive to never terminate the job)
  &lt;tt&gt;:kill_on_terminate&lt;/tt&gt;: skip archive and postpone_termination
</pre>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000106_source')" id="l_M000106_source">show source</a> ]</p>

  <div id="M000106_source" class="dyn-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 34</span>
34:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">options</span>={}, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
35:       <span class="ruby-ivar">@job_status</span> = <span class="ruby-identifier">:created</span>
36:       <span class="ruby-ivar">@job_lock</span> = <span class="ruby-constant">Mutex</span>.<span class="ruby-identifier">new</span>
37:       <span class="ruby-ivar">@job_key</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:key</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">gen_key</span>
38:       <span class="ruby-ivar">@job_args</span> = <span class="ruby-identifier">args</span>
39:       <span class="ruby-ivar">@job_statistics</span> = { <span class="ruby-identifier">:created_on</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span> }
40:       <span class="ruby-ivar">@job_progress</span> = <span class="ruby-value">0</span>
41:       <span class="ruby-ivar">@job_name</span> = <span class="ruby-identifier">name</span>
42:       <span class="ruby-ivar">@job_terminated</span> = <span class="ruby-keyword kw">false</span>
43:       <span class="ruby-ivar">@job_options</span> = <span class="ruby-ivar">@@job_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
44:       <span class="ruby-ivar">@job_result_valid</span> = <span class="ruby-keyword kw">true</span>
45:       <span class="ruby-ivar">@job</span> = <span class="ruby-keyword kw">nil</span>
46:       
47:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:ttl</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:infinitive</span> <span class="ruby-keyword kw">or</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:ttl</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
48:         <span class="ruby-ivar">@job_ttl_thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
49:           <span class="ruby-identifier">sleep</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:ttl</span>]
50:           <span class="ruby-identifier">terminate</span>
51:         <span class="ruby-keyword kw">end</span>
52:       <span class="ruby-keyword kw">end</span>
53:       
54:       <span class="ruby-ivar">@config</span> = <span class="ruby-constant">ActiveBackground</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">instance</span>
55:       <span class="ruby-ivar">@logger</span> = <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">logger</span>
56:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>

<div class="sectiontitle">Public Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000113"></a><b>archive</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000113_source')" id="l_M000113_source">show source</a> ]</p>

  <div id="M000113_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 157</span>
157:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">archive</span>
158:       <span class="ruby-comment cmt"># TODO: write results, options and arguments to file unless specified different</span>
159:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000124"></a><b>args</b>()
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000125">job_args</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000124_source')" id="l_M000124_source">show source</a> ]</p>

  <div id="M000124_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 189</span>
189:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">args</span>
190:       <span class="ruby-ivar">@job_args</span>
191:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000109"></a><b>define_job</b>(&amp;job)
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000109_source')" id="l_M000109_source">show source</a> ]</p>

  <div id="M000109_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 133</span>
133:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">define_job</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">job</span>)
134:       <span class="ruby-ivar">@job</span> = <span class="ruby-identifier">job</span>
135:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000130"></a><b>dump</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000130_source')" id="l_M000130_source">show source</a> ]</p>

  <div id="M000130_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 204</span>
204:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dump</span>
205:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">'Job: You need to implement dump'</span>)
206:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000111"></a><b>initiate_termination</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000111_source')" id="l_M000111_source">show source</a> ]</p>

  <div id="M000111_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 144</span>
144:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initiate_termination</span>
145:       <span class="ruby-identifier">sleep</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:postpone_termination</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:postpone_termination</span>]
146:       <span class="ruby-identifier">archive</span>
147:       <span class="ruby-comment cmt"># TODO: Need to cleanup the job</span>
148:       <span class="ruby-ivar">@job_status</span> = <span class="ruby-identifier">:terminated</span>
149:       <span class="ruby-ivar">@job_terminated</span> = <span class="ruby-keyword kw">true</span>
150:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' is terminated'</span>)
151:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000125"></a><b>job_args</b>()
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000124">args</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000117"></a><b>job_key</b>()
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000116">key</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000119"></a><b>job_progress</b>()
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000118">progress</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000129"></a><b>job_statistic</b>(key)
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000128">statistic</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000127"></a><b>job_statistics</b>()
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000126">statistics</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000121"></a><b>job_status</b>()
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000120">status</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000123"></a><b>job_status=</b>(status)
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000122">status=</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000134"></a><b>job_valid</b>()
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000133">valid</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000136"></a><b>job_valid=</b>(status)
  </div>
  <div class="description">

  <p>
Alias for <a href="Job.html#M000135">valid=</a>
</p>
  </div>
</div>
<div class="method">
  <div class="title">
    <a name="M000116"></a><b>key</b>()
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000117">job_key</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000116_source')" id="l_M000116_source">show source</a> ]</p>

  <div id="M000116_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 169</span>
169:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">key</span>
170:       <span class="ruby-ivar">@job_key</span>
171:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000115"></a><b>name</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000115_source')" id="l_M000115_source">show source</a> ]</p>

  <div id="M000115_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 165</span>
165:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">name</span>
166:       <span class="ruby-ivar">@job_name</span>
167:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000137"></a><b>no_valid_results</b>()
  </div>
  <div class="description">

  <p>
you can override this method to dump the failed results into a database or
log. But most of the time you just want to know that it failed and why it
failed so you can report this back.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000137_source')" id="l_M000137_source">show source</a> ]</p>

  <div id="M000137_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 232</span>
232:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">no_valid_results</span>()
233:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000107"></a><b>process</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000107_source')" id="l_M000107_source">show source</a> ]</p>

  <div id="M000107_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 58</span>
 58:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>
 59:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@job_status</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:created</span> <span class="ruby-keyword kw">or</span> <span class="ruby-ivar">@job_status</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:infinitive</span>
 60:       <span class="ruby-ivar">@job_status</span>=<span class="ruby-identifier">:started</span>
 61:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' started'</span>)
 62:       
 63:       <span class="ruby-keyword kw">begin</span>
 64:         <span class="ruby-comment cmt"># give the worker the chance to run procedures before starting work</span>
 65:         <span class="ruby-comment cmt"># the options is automaticly set if before_work exists can be</span>
 66:         <span class="ruby-comment cmt"># overwritten by manualy setting it to true</span>
 67:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:before_job</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-operator">!</span><span class="ruby-identifier">terminated?</span>
 68:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' is preparing with before_work'</span>)
 69:           <span class="ruby-identifier">before_job</span>(<span class="ruby-identifier">args</span>)
 70:         <span class="ruby-keyword kw">end</span>
 71:         
 72:         <span class="ruby-comment cmt"># start the job</span>
 73:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">terminated?</span>
 74:           <span class="ruby-ivar">@job_status</span>=<span class="ruby-identifier">:running</span>
 75:           <span class="ruby-ivar">@job_statistics</span>[<span class="ruby-identifier">:started_on</span>] = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
 76:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' processing'</span>)
 77:           <span class="ruby-identifier">process_job</span>
 78:           <span class="ruby-ivar">@job_status</span>=<span class="ruby-identifier">:processed</span>
 79:         <span class="ruby-keyword kw">end</span>
 80:         
 81:         <span class="ruby-comment cmt"># this method is used to write the results to database or pass</span>
 82:         <span class="ruby-comment cmt"># them on to an other application (by webservice)</span>
 83:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:after_job</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-operator">!</span><span class="ruby-identifier">terminated?</span>
 84:           <span class="ruby-ivar">@job_statistics</span>[<span class="ruby-identifier">:processed_on</span>] = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
 85:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' is finishing processing'</span>)
 86:           <span class="ruby-identifier">after_job</span>
 87:         <span class="ruby-keyword kw">end</span>
 88:         
 89:         <span class="ruby-comment cmt"># allows to validate the results, default true is passed but you can</span>
 90:         <span class="ruby-comment cmt"># reimplement the method to allow checking if everything went o.k.</span>
 91:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">valid?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">terminated?</span>
 92:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' results are invalid'</span>)
 93:           <span class="ruby-identifier">no_valid_results</span>
 94:         <span class="ruby-keyword kw">end</span>
 95:         
 96:         <span class="ruby-comment cmt"># this method allows you to cleanup things, most of the time you will</span>
 97:         <span class="ruby-comment cmt"># do the cleanup by using after_work, but if you have multiple methods</span>
 98:         <span class="ruby-comment cmt"># registerd and you don't know which method will run last you can use</span>
 99:         <span class="ruby-comment cmt"># cleanup to cleanup after running all after_work methods.</span>
100:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:cleanup</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-operator">!</span><span class="ruby-identifier">terminated?</span>
101:           <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">'Job: '</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">+</span> <span class="ruby-value str">' is cleaning up'</span>)
102:           <span class="ruby-identifier">cleanup</span>
103:         <span class="ruby-keyword kw">end</span>
104:         
105:         <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:ttl</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:infinitive</span>
106:           <span class="ruby-comment cmt"># TODO: integrate better, count run(s) and integrate a sleep pattern</span>
107:           <span class="ruby-ivar">@job_status</span> = <span class="ruby-identifier">:infinitive</span>
108:           <span class="ruby-identifier">process</span>
109:         <span class="ruby-keyword kw">else</span>
110:           <span class="ruby-ivar">@job_statistics</span>[<span class="ruby-identifier">:terminated_on</span>] = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>
111:           <span class="ruby-identifier">terminate</span> <span class="ruby-comment cmt"># we are done with working, lets mark this job for termination</span>
112:         <span class="ruby-keyword kw">end</span>
113:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
114:         <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">&quot;\n******************************************\n&quot;</span> <span class="ruby-operator">+</span>
115:                       <span class="ruby-node">&quot;Exception: #{e.to_s} - (#{e.class})\n&quot;</span> <span class="ruby-operator">+</span>
116:                       <span class="ruby-value str">&quot;Job: Cannot proces server\n&quot;</span> <span class="ruby-operator">+</span>
117:                       <span class="ruby-value str">&quot;----------------BACKTRACE-----------------\n&quot;</span> <span class="ruby-operator">+</span>
118:                                 <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n&quot;</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;\n&quot;</span> <span class="ruby-operator">+</span>
119:                       <span class="ruby-value str">&quot;-------------------END--------------------\n&quot;</span> <span class="ruby-operator">+</span>
120:                       <span class="ruby-value str">&quot;\n******************************************\n&quot;</span> )
121:         <span class="ruby-identifier">terminate</span>
122:       <span class="ruby-keyword kw">end</span>
123:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000108"></a><b>process_job</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000108_source')" id="l_M000108_source">show source</a> ]</p>

  <div id="M000108_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 125</span>
125:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_job</span>
126:       <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@job</span>
127:         <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-value str">'Job: You need to implement process_job'</span>)
128:       <span class="ruby-keyword kw">else</span>
129:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&amp;</span><span class="ruby-ivar">@job</span>)
130:       <span class="ruby-keyword kw">end</span>
131:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000118"></a><b>progress</b>()
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000119">job_progress</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000118_source')" id="l_M000118_source">show source</a> ]</p>

  <div id="M000118_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 174</span>
174:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">progress</span>
175:       <span class="ruby-ivar">@job_progress</span>
176:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000114"></a><b>recover_from_archive</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000114_source')" id="l_M000114_source">show source</a> ]</p>

  <div id="M000114_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 161</span>
161:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">recover_from_archive</span>
162:       <span class="ruby-comment cmt"># TODO: recover results, options and arguments from file and provide a interface</span>
163:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000139"></a><b>start</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000139_source')" id="l_M000139_source">show source</a> ]</p>

  <div id="M000139_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 239</span>
239:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">start</span>
240:       <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>.<span class="ruby-identifier">start</span>
241:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000128"></a><b>statistic</b>(key)
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000129">job_statistic</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000128_source')" id="l_M000128_source">show source</a> ]</p>

  <div id="M000128_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 199</span>
199:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">statistic</span>(<span class="ruby-identifier">key</span>)
200:       <span class="ruby-ivar">@job_statistics</span>[<span class="ruby-identifier">key</span>]
201:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000126"></a><b>statistics</b>()
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000127">job_statistics</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000126_source')" id="l_M000126_source">show source</a> ]</p>

  <div id="M000126_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 194</span>
194:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">statistics</span>
195:       <span class="ruby-ivar">@job_statistics</span>
196:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000120"></a><b>status</b>()
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000121">job_status</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000120_source')" id="l_M000120_source">show source</a> ]</p>

  <div id="M000120_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 179</span>
179:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">status</span>
180:       <span class="ruby-ivar">@job_status</span>
181:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000122"></a><b>status=</b>(status)
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000123">job_status=</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000122_source')" id="l_M000122_source">show source</a> ]</p>

  <div id="M000122_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 184</span>
184:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">status=</span>(<span class="ruby-identifier">status</span>)
185:       <span class="ruby-ivar">@job_status</span>=<span class="ruby-identifier">status</span>
186:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000138"></a><b>stop</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000138_source')" id="l_M000138_source">show source</a> ]</p>

  <div id="M000138_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 235</span>
235:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stop</span>
236:       <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>.<span class="ruby-identifier">stop</span>
237:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000110"></a><b>terminate</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000110_source')" id="l_M000110_source">show source</a> ]</p>

  <div id="M000110_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 137</span>
137:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">terminate</span>
138:       <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:ttl</span>]=<span class="ruby-keyword kw">nil</span>
139:       <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
140:         <span class="ruby-identifier">initiate_termination</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@job_options</span>[<span class="ruby-identifier">:terminate</span>]
141:       <span class="ruby-keyword kw">end</span>
142:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000112"></a><b>terminated?</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000112_source')" id="l_M000112_source">show source</a> ]</p>

  <div id="M000112_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 153</span>
153:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">terminated?</span>
154:       <span class="ruby-ivar">@job_terminated</span>
155:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000133"></a><b>valid</b>()
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000134">job_valid</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000133_source')" id="l_M000133_source">show source</a> ]</p>

  <div id="M000133_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 219</span>
219:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid</span>
220:       <span class="ruby-ivar">@job_result_valid</span>
221:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000135"></a><b>valid=</b>(status)
  </div>
<div class="aka">
  This method is also aliased as
  <a href="Job.html#M000136">job_valid=</a>
</div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000135_source')" id="l_M000135_source">show source</a> ]</p>

  <div id="M000135_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 224</span>
224:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid=</span>(<span class="ruby-identifier">status</span>)
225:       <span class="ruby-ivar">@job_result_valid</span>=<span class="ruby-identifier">status</span>
226:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000131"></a><b>valid?</b>()
  </div>
  <div class="description">

  <p>
check if the work that has been done is valid. If the result is not valid
the results are logged and <a href="Job.html#M000137">no_valid_results</a>
is called.
</p>
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000131_source')" id="l_M000131_source">show source</a> ]</p>

  <div id="M000131_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 211</span>
211:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">valid?</span>
212:       <span class="ruby-ivar">@job_result_valid</span>
213:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
<div class="method">
  <div class="title">
    <a name="M000132"></a><b>validate</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000132_source')" id="l_M000132_source">show source</a> ]</p>

  <div id="M000132_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 215</span>
215:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validate</span>
216:       <span class="ruby-ivar">@logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-value str">'Job: You need to implement validate'</span>)
217:     <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>

<div class="sectiontitle">Private Instance methods</div>
<div class="method">
  <div class="title">
    <a name="M000140"></a><b>gen_key</b>()
  </div>
<div class="sourcecode">
  <p class="source-link">[ <a href="javascript:toggleSource('M000140_source')" id="l_M000140_source">show source</a> ]</p>

  <div id="M000140_source" class="dyn-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_background/tasks/../lib/active_background/job.rb, line 244</span>
244:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">gen_key</span>
245:         <span class="ruby-identifier">key</span> = <span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">MD5</span>.<span class="ruby-identifier">hexdigest</span>(<span class="ruby-node">&quot;#{inspect}#{Time.now}#{rand}&quot;</span>)
246:       <span class="ruby-keyword kw">end</span>
</pre>
  </div>
</div>
</div>
</div>

  </div>

    </body>
</html>